package com.mentaleye.service.impl;

import com.mentaleye.bean.StudentActivityBean;
import com.mentaleye.dal.dao.StudentActivityDao;
import com.mentaleye.dal.model.StudentActivity;
import com.mentaleye.service.StudentActivityService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import com.mentaleye.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentActivityServiceImpl implements StudentActivityService{

	@Autowired private StudentActivityDao studentActivityDao;
	@Override
	public void queryStuActByPage(CommonPage commonPage) {
		@SuppressWarnings("unchecked")
		List<StudentActivityBean> list = ObjectUtil.transferList(studentActivityDao.selectByMap(commonPage.pageToMap()),StudentActivityBean.class);
		commonPage.setPageData(list);
	}
	@Override
	public CommonResult addActivity(StudentActivityBean studentActivityBean) {
		CommonResult commonResult = new CommonResult();
		StudentActivity studentActivity = (StudentActivity) ObjectUtil.transfer(studentActivityBean, StudentActivity.class);
		boolean boo = studentActivityDao.addStuActivity(studentActivity);
		commonResult.setIsSuccess(boo);
		return commonResult;
	}
	@Override
	public CommonResult updatActivity(StudentActivityBean studentActivityBean) {
		CommonResult commonResult = new CommonResult();
		StudentActivity studentActivity = (StudentActivity) ObjectUtil.transfer(studentActivityBean, StudentActivity.class);
		boolean boo = studentActivityDao.updateStuActivity(studentActivity);
		commonResult.setIsSuccess(boo);
		return commonResult;
	}
	@Override
	public StudentActivityBean queryByActivityId(Integer activityId) {
		StudentActivityBean studentActivityBean = (StudentActivityBean) ObjectUtil.transfer(studentActivityDao.selectById(activityId),StudentActivityBean.class);
		return studentActivityBean;
	}
	@Override
	public CommonResult updateStatusById(StudentActivityBean studentActivityBean) {
		CommonResult commonResult = new CommonResult();
		StudentActivity studentActivity = (StudentActivity) ObjectUtil.transfer(studentActivityBean, StudentActivity.class);
		boolean boo = studentActivityDao.updateStatusById(studentActivity);
		commonResult.setIsSuccess(boo);
		return commonResult;
	}

	@Override
	public CommonResult updateByPrimaryKeySelectiveById(StudentActivityBean studentActivityBean) {
		CommonResult commonResult = new CommonResult();
		StudentActivity studentActivity = (StudentActivity) ObjectUtil.transfer(studentActivityBean, StudentActivity.class);
		boolean boo = studentActivityDao.updateByPrimaryKeySelectiveById(studentActivity);
		commonResult.setIsSuccess(boo);
		return commonResult;
	}

}
